package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface AddressBookMapper {

    void insert(AddressBook addressBook);

    List<AddressBook> getByUserId(Long userId);

    void updateByUserId(AddressBook addressBook);

    void updateById(AddressBook addressBook);

    @Select("SELECT * FROM `address_book` WHERE `id` = #{id}")
    AddressBook getById(Long id);

    @Select("SELECT * FROM `address_book` WHERE `user_id` = #{userId} AND `is_default` = #{isDefault}")
    AddressBook getByDefault(AddressBook addressBook);

    @Delete("DELETE FROM `address_book` WHERE `id` = #{id}")
    void deleteById(Long id);
}
